cmake_minimum_required(VERSION 3.15)
# 3.0以上版本才允许使用VERSION option
project(JsonTest VERSION 1.0.0 LANGUAGES C)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR})
find_package(cJSON REQUIRED)
if(MSVC)
	#关闭C4819警告
	add_definitions("/wd4819")
	message(STATUS "optional:/wd4819")
	#关闭CRT_SECURE警告
	add_definitions(-D_CRT_SECURE_NO_WARNINGS)
	message(STATUS "optional:-D_CRT_SECURE_NO_WARNINGS")
endif(MSVC)

add_library(jsonlib src/jsonlib.c)
target_include_directories(jsonlib PUBLIC include)
target_link_libraries(jsonlib PUBLIC cjson)
target_compile_definitions(jsonlib 
    PRIVATE $<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,SHARED_LIBRARY>:JSONLIB_EXPORTS>
    PUBLIC $<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,SHARED_LIBRARY>:JSONLIB_IS_DLL>
)

set_target_properties(jsonlib PROPERTIES PUBLIC_HEADER "include/jsonlib.h")
install(TARGETS jsonlib DESTINATION "."
        PUBLIC_HEADER DESTINATION include
        RUNTIME DESTINATION bin
        ARCHIVE DESTINATION lib
        LIBRARY DESTINATION lib
        )
